package mblog.core.persist.service.impl;

import mblog.core.persist.dao.ResourceAttachDao;
import mblog.core.persist.entity.PostPO;
import mblog.core.persist.entity.ResourceAttachPO;
import mblog.core.persist.service.ResourceAttachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResourceAttachServiceImpl implements ResourceAttachService {
    @Autowired
    private ResourceAttachDao resourceAttachDao;

    @Override
    public void batchPost(PostPO po, List<ResourceAttachPO> attaches) {
        resourceAttachDao.deleteByPostId(po.getId());
        for (ResourceAttachPO d : attaches) {
            d.setPostId(po.getId());
            resourceAttachDao.save(d);
        }
    }

    @Override
    public List<ResourceAttachPO> loadByPostId(long postId) {
        return resourceAttachDao.findByPostId(postId);
    }
}
